home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’97 / Warrior’s Progress / source code / Source / Libraries / Trees / TreeNode.h < prev   
Encoding:
Text File  |  1997-06-28  |  1.7 KB  |  68 lines  |  [TEXT/CWIE]

  1. // TreeNode.h
  2.  
  3. #ifndef TreeNode_h
  4. #define TreeNode_h
  5.  
  6. #ifndef Assert_h
  7. #include "Assert.h"
  8. #endif
  9.  
  10. class TreeNode
  11.   {
  12.     friend class Tree;
  13.     
  14.     private:
  15.         Tree *tree;
  16.         TreeNode *parent;
  17.         TreeNode *left;
  18.         TreeNode *right;
  19.         
  20.         // not implemented:
  21.             TreeNode( const TreeNode& );
  22.             void operator=( const TreeNode& );
  23.     
  24.         TreeNode*& LinkFromAbove();
  25.         
  26.         TreeNode *NextNode() const;
  27.         TreeNode *PreviousNode() const;
  28.         TreeNode *SiblingNode() const;
  29.         
  30.     public:
  31.         TreeNode();
  32.         ~TreeNode();
  33.         
  34.         bool Owned() const                        { return tree != 0; }
  35.         Tree& Owner() const                        { Assert( tree != 0 ); return *tree; }
  36.  
  37.         const TreeNode *Parent() const        { return parent; }
  38.         const TreeNode *Left() const            { return left; }
  39.         const TreeNode *Right() const            { return right; }
  40.         const TreeNode *Next() const            { return NextNode(); }
  41.         const TreeNode *Previous() const        { return PreviousNode(); }
  42.         const TreeNode *Sibling() const        { return SiblingNode(); }
  43.  
  44.         TreeNode *Parent()                        { return parent; }
  45.         TreeNode *Left()                            { return left; }
  46.         TreeNode *Right()                            { return right; }
  47.         TreeNode *Next()                            { return NextNode(); }
  48.         TreeNode *Previous()                        { return PreviousNode(); }
  49.         TreeNode *Sibling()                        { return SiblingNode(); }
  50.         
  51.         bool IsRoot() const                        { return parent == 0; }
  52.         bool IsLeftChild() const                { return parent != 0 && parent->left == this; }
  53.         bool IsRightChild() const                { return parent != 0 && parent->right == this; }
  54.         
  55.         bool HasLeftChild() const                { return left != 0; }
  56.         bool HasRightChild() const                { return right != 0; }
  57.         bool IsLeaf() const                        { return left == 0 && right == 0; }
  58.         
  59.         void SwapWith( TreeNode& );
  60.         void RotateUp();
  61.         
  62.         uint32 Depth() const;
  63.         
  64.         bool Valid() const;                        // Should always be true
  65.   };
  66.  
  67. #endif
  68.